/*
 * AllwinnerTech hdmi cec driver
 *
 * Copyright (C) 2015 AllwinnerTech Corporation
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#define CEC_EOM_BLOCK_INVALID	(-1)
#define CEC_EOM_BLOCK_MORE		(0)
#define CEC_EOM_BLOCK_END		(1)

/* timing define for cec send */
#define CEC_START_BIT_LOW_TIME	(3700000)
#define CEC_START_BIT_HIGH_TIME	(800000)

#define CEC_BIT_WHOLE_TIME		(2400000)
#define CEC_LOGIC_0_LOW_TIME	(1500000)
#define CEC_LOGIC_1_LOW_TIME	(600000)

#define CEC_LOGIC_0_HIGH_TIME	(CEC_BIT_WHOLE_TIME - CEC_LOGIC_0_LOW_TIME)
#define CEC_LOGIC_1_HIGH_TIME	(CEC_BIT_WHOLE_TIME - CEC_LOGIC_1_LOW_TIME)

#define	CEC_BYTE_ACK_SAMPLE_TIME	(400000)
#define CEC_BYTE_ACK_COMPLETE_TIME \
	(CEC_BIT_WHOLE_TIME - CEC_LOGIC_1_LOW_TIME - CEC_BYTE_ACK_SAMPLE_TIME)

#define CEC_START_BIT_TOTAL_MAX		(4800000)
#define CEC_START_BIT_TOTAL_MIN		(4000000)

/* error define */
#define	CEC_TRANSMIT_OK			(0)
#define CEC_TRANSMIT_NO_INPUT	(1)
#define CEC_TRANSMIT_LINE_BUSY	(2)
#define CEC_TRANSMIT_ACK_ERROR	(3)
#define CEC_TRANSMIT_ADDRESS_ERROR	(4)
#define	CEC_TRANSMIT_UNKNOW_ERROR	(5)

/* next transmit free time */
#define CEC_DEFAULT_PERIOD		(7)

#define CEC_MAKE_HEADER(_src_la, _dst_la) \
	(((_src_la<<4) & 0xf0) | (_dst_la & 0x0f))
#define CEC_GET_INITIATOR(_byte)	((_byte>>4) & 0x0f)
#define CEC_GET_DESTINATION(_byte)	(_byte & 0x0f)

struct hdmi_cec_frame {
	int initiator;
	int destination;
	/* total of opcode and operands */
	int operand_num;
	/* operand[0] is the opcode
     * the remain is operands */
	int operand[16];
};
